package com.example.androidnote.main;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import android.os.Bundle;

import com.common.common.BaseActivity;
import com.common.common.BasePresenter;
import com.example.androidnote.R;
import com.example.androidnote.domain.MainDomain;

import butterknife.BindView;

public class MainActivity extends BaseActivity<MainContract.IMainPresenter> implements MainContract.IMainView {

    @BindView(R.id.rv_activity_main)
    RecyclerView rvMain;
    @BindView(R.id.srl_activity_main)
    SwipeRefreshLayout srlMain;
    private MainAdapter mMainAdapter;

    @Override
    protected MainContract.IMainPresenter createPresenter() {
        return new MainPresenter(this);
    }

    @Override
    protected void initParams(Bundle bundle) {

    }

    @Override
    protected int bindLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        srlMain.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                srlMain.setRefreshing(true);
                mPresenter.getChapter();
            }
        });
        rvMain.setLayoutManager(new LinearLayoutManager(this));
        mMainAdapter = new MainAdapter(R.layout.item_activity_main);
        rvMain.setAdapter(mMainAdapter);
    }

    @Override
    protected void initData() {
        mPresenter.getChapter();
    }

    @Override
    public void showMainPage(MainDomain.MainEntity mainEntity) {
        srlMain.setRefreshing(false);
        mMainAdapter.setNewData(mainEntity.getData());
    }
}
